﻿using Lcygcc.Domain.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lcygcc.Domain.Repository.Entity.JKModel;
using Lcygcc.Infrastructure.Repository;

namespace Lcygcc.Domain.ServiceImpl
{
    /// <summary>
    /// 卡系列服务类
    /// </summary>
    public class CardTypeService : ICardTypeService
    {
        private readonly IBaseRepository mBaseRepository = null;
        public CardTypeService(IBaseRepository baseRepository)
        {
            mBaseRepository = baseRepository;
        }
        /// <summary>
        /// 增加卡系列
        /// </summary>
        /// <param name="cardSeriesList"></param>
        public void Save(List<CardType> cardSeriesList)
        {
            List<CardType> insertList = new List<CardType>();
            List<string> listId = cardSeriesList.Select(it => it.Id).ToList();
            if (listId.Count > 0)
            {
                var list = GetAll();
                if (list != null && list.Count > 0)
                {
                    insertList = list.Where(it => !listId.Contains(it.Id)).ToList();
                }
                else
                {
                    insertList = cardSeriesList;
                }
                if (insertList.Count > 0)
                {
                    mBaseRepository.db.Insertable<CardType>(insertList).ExecuteCommand();//保存卡系列
                }
            }
        }
        /// <summary>
        /// 查询卡系列
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CardType Get(string id)
        {
            return mBaseRepository.db.Queryable<CardType>().Where(it => it.Id == id).FirstOrDefault();
        }
        /// <summary>
        /// 查询所有卡系列
        /// </summary>
        /// <returns></returns>
        public List<CardType> GetAll()
        {
            return mBaseRepository.db.Queryable<CardType>().ToList();
        }
    }
}
